package com.sinven.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinven.mapper.MessageMapper;
import com.sinven.pojo.Message;
@Service
public class MessageServiceImpl implements MessageService{
		@Autowired
		private MessageMapper messageMapper;

		@Override
		public boolean AddMessage(Message message) throws Exception {
			int res=messageMapper.AddMessage(message);
			if(res>0) {
				System.out.println("添加失败");
				return false;
			}
			return true;
		}

		@Override
		public boolean DeletedMessage(long m_id) throws Exception {
			int res=messageMapper.DeletedMessage(m_id);
			if(res>0) {
				System.out.println("删除失败");
				return false;
			}
			return true;
		}

		@Override
		public Message SelectAllMessageBySelf(long m_fromuserId) throws Exception {
			Message message=messageMapper.SelectAllMessageBySelf(m_fromuserId);
			if(message==null) {
				System.out.println("查询失败");
				return null;
			}
			return message;
		}

		@Override
		public long SelectMessageCountBySelf(long m_fromuserId) throws Exception {
			long count=messageMapper.SelectMessageCountBySelf(m_fromuserId);
			if(count>0) {
				return count;
			}
			return 0;
		}

		@Override
		public List<Message> SelectMessageByOther(long m_touserId) throws Exception {
			List<Message> message= messageMapper.SelectMessageByOther(m_touserId);
			if(message==null) {
				System.out.println("查询失败");
				return null;
			}
			return message;
		}

		@Override
		public long SelectAllMessageByOther(long m_touserId) throws Exception {
			long count=messageMapper.SelectAllMessageByOther(m_touserId);
			if(count>0) {
				return count;
			}
			return 0;
		}

		@Override
		public Message SelectOneMessage(long m_id) throws Exception {
			Message message=messageMapper.SelectOneMessage(m_id);
			if(message==null) {
				System.out.println("查询失败");
				return null;
			}
			return message;
		}
		
}
